<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type"content="text/html;charset=utf-8">
<title>图书表管理</title>
<style>
    body{font-size:12px;}
    td{font-size:12px;}
</style>
</head>
<body>

                    <h1>图书管理</h1>

                    <a href="index.php?action=list">图书列表</a>||
                    <a href="index.php?action=add">添加图书</a>||
                    <a href="index.php?action=ser">搜索图书</a>
                    <hr>
    <?php
        include 'func.inc.php';
        if(@$_GET['action']=="add"){
                include 'add.inc.php';
        }elseif(@$_GET['action']=="insert"){
            $up = upload();
            if(!$up[0]){
                die($up[1]);
            }
            include 'conn.inc.php';
            $sql = "insert into books(bookname,publisher,author,price,ptime,pic,detail)
                values('{$_POST["bookname"]}','{$_POST["publisher"]}','{$_POST["author"]}','
                {$_POST["price"]}','".time()."','{$up[1]}','{$_POST["detail"]}')";
            $result = mysql_query($sql);
            if($result && mysql_affected_rows() > 0){
                echo "插入一条数据成功！";
            }else{
                echo "数据录入失败，请重试！";
            }
            mysql_close($link);
        }elseif(@$_GET['action']=='mod'){
            include 'mod.inc.php';
        }elseif(@$_GET['action']=='update'){
            if($_FILES["pic"]["error"]=="0"){
                $up = upload();
                if($up[0]){
                    $pic = $up[1];
                }else{
                    die($up[1]);
                }
            }else{
                $pic = $_POST["picname"];
                var_dump($pic);
            }
            include 'conn.inc.php';
            $sql = "update books set bookname ='{$_POST["bookname"]}',publisher ='{$_POST["publisher"]}',author ='{$_POST["author"]}',price ='{$_POST["price"]}',pic ='{$pic}',detail ='{$_POST["detail"]}' where id={$_POST['id']}";
            $result = mysql_query($sql);      
            if($result && mysql_affected_rows() > 0){
                if(@$up[0]){
                    delpic($_POST["picname"]);
                }else{
                    echo "记录修改成功！";
                }
            }else{
                    echo "数据修改失败，请重试！";
                }
            mysql_close($link);
        }elseif(@$_GET['action']== "del"){
            include 'conn.inc.php';
            $result = mysql_query("delete from books where id='{$_GET["id"]}'");
            if($result && mysql_affected_rows() > 0){
                delpic($_GET['pic']);
                echo '<script>window.location = "'.$_SERVER["HTTP_REFERER"].'" <script>';
            }else{
                echo "数据删除失败！";
            }
            mysql_close($link);
        }elseif(@$_GET['action']=='ser'){
            include 'ser.inc.php';
        }else{
            include 'list.inc.php';
        }
    ?>
    

</body>
</html>